package com.qisu.command;

import javax.annotation.PostConstruct;

import org.springframework.stereotype.Component;

import com.qisu.converters.Converters;

import io.netty.channel.ChannelHandlerContext;

/**
 * 充电桩签到
 * @author li
 *
 */
@Component
public class CMD106 extends AbstractSinexcelCmd {

	@PostConstruct
	@Override
	protected void init() {
		super.init();

		fieldsList.addField(new CommandFieldDef<Integer>(2))
				.addField(new CommandFieldDef<Integer>(2))
				.addField(new CommandFieldDef<String>(32, Converters.strConverter, "充电桩ID"))
				.addField(new CommandFieldDef<Byte>(1))
				.addField(new CommandFieldDef<Integer>(4, Converters.intConverter, "充电桩软件版本"))
				.addField(new CommandFieldDef<Integer>(2))
				.addField(new CommandFieldDef<Integer>(4, Converters.intConverter, "启动次数"))
				.addField(new CommandFieldDef<Byte>(1, Converters.byteConverter, "数据上传模式"))
				.addField(new CommandFieldDef<Integer>(2, Converters.seIntConverter, "签到间隔"))
				.addField(new CommandFieldDef<Byte>(1, Converters.byteConverter, "工作模式"))
				.addField(new CommandFieldDef<Byte>(1, Converters.byteConverter, "充电枪数量"))
				.addField(new CommandFieldDef<Byte>(1, Converters.byteConverter, "心跳上报周期"))
				.addField(new CommandFieldDef<Byte>(1, Converters.byteConverter, "心跳包核工测超时次数"))
				.addField(new CommandFieldDef<Integer>(4, Converters.intConverter, "充电记录数量"))
				.addField(new CommandFieldDef<String>(8, Converters.hexConverter, "当前充电桩系统时间"));
	}

	@Override
	protected void processCmd(ChannelHandlerContext ctx,byte[] req) {
//		String pileSerial = fieldsList.getValue("充电桩ID");
		/*HashMap<String, Object> packetData = new HashMap<String, Object>() {
			private static final long serialVersionUID = 3472444223637573205L;

			{
				put("充电桩ID", fieldsList.getValue("充电桩ID"));
				put("充电桩软件版本", fieldsList.getValue("充电桩软件版本"));
				put("启动次数", fieldsList.getValue("启动次数"));
				put("数据上传模式", fieldsList.getValue("数据上传模式"));
				put("签到间隔", fieldsList.getValue("签到间隔"));
				put("工作模式", fieldsList.getValue("工作模式"));
				put("充电枪数量", fieldsList.getValue("充电枪数量"));
				put("心跳上报周期", fieldsList.getValue("心跳上报周期"));
				put("心跳包核工测超时次数", fieldsList.getValue("心跳包核工测超时次数"));
				put("充电记录数量", fieldsList.getValue("充电记录数量"));
				put("当前充电桩系统时间", fieldsList.getValue("当前充电桩系统时间"));
			}
		};*/

		// _pile.setWorkingStatus(pileSerial, WorkingStatus.Signing);
		responseClient(ctx);
	}

	@Override
	protected void responseClient(ChannelHandlerContext ctx) {
		// cmd=105
		// @formatter:off
		byte[] p = new byte[] {
			(byte)0xAA, (byte)0xF5,		// signature
			(byte)0x0D, (byte)0x00, 	// length
			(byte)0x10, 				// version
			(byte)0x00,					// sequence
			(byte)0x69, (byte)0x00, 	// command
			(byte)0x00, (byte)0x00, 	// preserved1
			(byte)0x00, (byte)0x00,		// preserved2
			(byte)0x69					// checksum
		};

//		setCommand(p, 105);
//		send(ctx, p);
		ctx.writeAndFlush(p);
	}

}
